﻿
using MelonLoader;
using MOD_TaiYangQiu.common;
using MOD_TaiYangQiu.config;
using MOD_TaiYangQiu.enums;
using MOD_TaiYangQiu.model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using UnityEngine;
using static WorldUnitData;

namespace MOD_TaiYangQiu.business
{
    public class CoupleUpgrade
    {
        CommonUtil commonUtil = new CommonUtil();
        /// <summary>
        /// 福利补贴
        /// </summary>
        public void WelfareBenefits()
        {
            LogUtil.Log("太阳球MOD", "福利发放");
            //主角信息
            WorldUnitBase protagonist = g.world.playerUnit;
            GradeLevel myLevel = commonUtil.GetNpcGradeLevel(g.world.playerUnit.data);
            WorldUnitData protagonistData = protagonist.data;
            Il2CppSystem.Collections.Generic.List<DataProps.PropsData> martialProps = new Il2CppSystem.Collections.Generic.List<DataProps.PropsData>();
            if (BaseConfig.isStudyMartial)
            {
                //获取积木空间功法
                martialProps = commonUtil.GetTownStorage();
            }
            //-----------------获取npc对象
            //妻子
            Il2CppSystem.Collections.Generic.List<string> wife = protagonistData.GetRelation(UnitBothRelationType.Married);
            if (BaseConfig.isWife)
            {
                LogUtil.Log("太阳球MOD", "妻子数量：" + wife.Count);
                foreach (string npcName in wife)
                {
                    AddUpgradeItems(npcName, "妻子", myLevel, martialProps);
                }

            }

            //道侣
            Il2CppSystem.Collections.Generic.List<string> couple = protagonistData.GetRelation(UnitBothRelationType.Lover);
            if (BaseConfig.isCouple)
            {
                LogUtil.Log("太阳球MOD", "道侣数量：" + couple.Count);
                foreach (string npcName in couple)
                {
                    AddUpgradeItems(npcName, "道侣", myLevel, martialProps);
                }
            }


            //师傅
            Il2CppSystem.Collections.Generic.List<string> teacher = protagonistData.GetRelation(UnitBothRelationType.Master);
            if (BaseConfig.isTeacher)
            {
                LogUtil.Log("太阳球MOD", "师傅数量：" + teacher.Count);
                foreach (string npcName in teacher)
                {
                    AddUpgradeItems(npcName, "师傅", myLevel, martialProps);
                }
            }

            //徒弟
            Il2CppSystem.Collections.Generic.List<string> student = protagonistData.GetRelation(UnitBothRelationType.Student);
            if (BaseConfig.isStudent)
            {
                LogUtil.Log("太阳球MOD", "徒弟数量：" + student.Count);
                foreach (string npcName in student)
                {
                    AddUpgradeItems(npcName, "徒弟", myLevel, martialProps);
                }
            }
            //父母
            Il2CppSystem.Collections.Generic.List<string> parents = protagonistData.GetRelation(UnitBothRelationType.Parents);
            if (BaseConfig.isParent)
            {
                LogUtil.Log("太阳球MOD", "父母数量：" + parents.Count);
                foreach (string npcName in parents)
                {
                    AddUpgradeItems(npcName, "父母", myLevel, martialProps);
                }
            }
            //子女
            Il2CppSystem.Collections.Generic.List<string> children = protagonistData.GetRelation(UnitBothRelationType.Children);
            if (BaseConfig.isChildren)
            {
                LogUtil.Log("太阳球MOD", "子女数量：" + children.Count);
                foreach (string npcName in children)
                {
                    AddUpgradeItems(npcName, "子女", myLevel, martialProps);
                }
            }
            //兄弟
            Il2CppSystem.Collections.Generic.List<string> brother = protagonistData.GetRelation(UnitBothRelationType.Brother);
            if (BaseConfig.isBrother)
            {
                LogUtil.Log("太阳球MOD", "兄弟姐妹数量：" + brother.Count);
                foreach (string npcName in brother)
                {
                    AddUpgradeItems(npcName, "兄弟姐妹", myLevel, martialProps);
                }
            }

            //宗门
            if (BaseConfig.school.IsSchool)
            {
                MapBuildSchool mySchool = g.world.playerUnit.data.school;
                LogUtil.Log("太阳球MOD", "判断玩家是否有宗门");
                if (mySchool != null)
                {
                    SchoolPostType myPost = mySchool.buildData.GetPostType(g.world.playerUnit.data.unitData.unitID);
                    //如果是宗主 则给宗门弟子发放福利
                    if (myPost == SchoolPostType.SchoolMain)
                    {
                        LogUtil.Log("太阳球MOD", "是宗主");
                        Il2CppSystem.Collections.Generic.List<MapBuildSchool> allSchool = mySchool.GetAllSchools(true);

                        foreach (MapBuildSchool school in allSchool)
                        {
                            int count = school.buildData.GetNPCManNum();
                            string schoolName = school.GetName(true);
                            if (!BaseConfig.school.IsPointSchool)
                            {
                                //分舵不发放
                                bool isPointSchool = school.IsTopSchool();
                                if (!isPointSchool)
                                {
                                    LogUtil.Log("太阳球MOD", string.Format("宗门名称：【{0}】是分舵不发放资源", schoolName));
                                    continue;
                                }
                            }

                            LogUtil.Log("太阳球MOD", string.Format("宗门名称：【{0}】 宗门人数：【{1}】", schoolName, count));
                            if (BaseConfig.school.IsDaZhangLao)
                            {
                                //大长老
                                Il2CppSystem.Collections.Generic.List<string> daZhangLao = school.buildData.npcBigElders;
                                foreach (string npcName in daZhangLao)
                                {
                                    bool isCan = commonUtil.HasRelation(wife, couple, teacher, student, parents, children, brother, npcName);
                                    if (isCan)
                                    {
                                        AddUpgradeItems(npcName, "宗门大长老", myLevel, martialProps, schoolName);
                                    }

                                }
                            }
                            if (BaseConfig.school.IsZhangLao)
                            {
                                //长老
                                Il2CppSystem.Collections.Generic.List<string> zhangLao = school.buildData.npcElders;
                                foreach (string npcName in zhangLao)
                                {
                                    bool isCan = commonUtil.HasRelation(wife, couple, teacher, student, parents, children, brother, npcName);
                                    if (isCan)
                                    {
                                        AddUpgradeItems(npcName, "宗门长老", myLevel, martialProps, schoolName);
                                    }

                                }
                            }
                            if (BaseConfig.school.IsZhenChuan)
                            {
                                //真传
                                Il2CppSystem.Collections.Generic.List<string> zhenChuan = school.buildData.npcInherit;
                                foreach (string npcName in zhenChuan)
                                {
                                    bool isCan = commonUtil.HasRelation(wife, couple, teacher, student, parents, children, brother, npcName);
                                    if (isCan)
                                    {
                                        AddUpgradeItems(npcName, "真传弟子", myLevel, martialProps, schoolName);
                                    }

                                }
                            }
                            if (BaseConfig.school.IsNeiMen)
                            {
                                //内门
                                Il2CppSystem.Collections.Generic.List<string> neiMeng = school.buildData.npcIn;
                                foreach (string npcName in neiMeng)
                                {
                                    bool isCan = commonUtil.HasRelation(wife, couple, teacher, student, parents, children, brother, npcName);
                                    if (isCan)
                                    {
                                        AddUpgradeItems(npcName, "内门弟子", myLevel, martialProps, schoolName);
                                    }

                                }
                            }
                            if (BaseConfig.school.IsWaiMen)
                            {
                                //外门
                                Il2CppSystem.Collections.Generic.List<string> waiMeng = school.buildData.npcOut;
                                foreach (string npcName in waiMeng)
                                {
                                    bool isCan = commonUtil.HasRelation(wife, couple, teacher, student, parents, children, brother, npcName);
                                    if (isCan)
                                    {
                                        AddUpgradeItems(npcName, "外门弟子", myLevel, martialProps, schoolName);
                                    }

                                }
                            }
                        }
                    }
                }

            }



        }
        /// <summary>
        /// 给npc添加突破材料
        /// </summary>
        /// <param name="npcNames"></param>
        private void AddUpgradeItems(string npcName, string relation, GradeLevel myLevel, Il2CppSystem.Collections.Generic.List<DataProps.PropsData> martialProps, string schoolName = "")
        {
            if (npcName == null)
            {
                return;
            }

            try
            {
                WorldUnitBase unitNPC = g.world.unit.GetUnit(npcName);
                if (unitNPC == null)
                {
                    return;
                }
                string npcRealName = unitNPC.data.unitData.propertyData.GetName();

                //境界
                GradeLevel gradeLevel = commonUtil.GetNpcGradeLevel(unitNPC.data);
                string gradeName = "";
                //获取境界名称
                if (true)
                {
                    if (gradeLevel == GradeLevel.LianQi_Q || gradeLevel == GradeLevel.LianQi_Z || gradeLevel == GradeLevel.LianQi_H)
                    {
                        //npc练气
                        gradeName = "lianQi";
                    }

                    else if (gradeLevel == GradeLevel.ZhuJi_Q || gradeLevel == GradeLevel.ZhuJi_Z || gradeLevel == GradeLevel.ZhuJi_H)
                    {
                        //npc筑基
                        gradeName = "zhuJi";

                    }
                    else if (gradeLevel == GradeLevel.JieJing_Q || gradeLevel == GradeLevel.JieJing_Z || gradeLevel == GradeLevel.JieJing_H)
                    {
                        //npc结晶
                        gradeName = "jieJing";

                    }
                    else if (gradeLevel == GradeLevel.JinDan_Q || gradeLevel == GradeLevel.JinDan_Z || gradeLevel == GradeLevel.JinDan_H)
                    {
                        //npc金丹
                        gradeName = "jinDan";

                    }
                    else if (gradeLevel == GradeLevel.JuLing_Q || gradeLevel == GradeLevel.JuLing_Z || gradeLevel == GradeLevel.JuLing_H)
                    {
                        //npc具灵
                        gradeName = "juLing";
                    }
                    else if (gradeLevel == GradeLevel.YuanYing_Q || gradeLevel == GradeLevel.YuanYing_Z || gradeLevel == GradeLevel.YuanYing_H)
                    {
                        //npc元婴
                        gradeName = "yuanYing";
                    }
                    else if (gradeLevel == GradeLevel.HuaShen_Q || gradeLevel == GradeLevel.HuaShen_Z || gradeLevel == GradeLevel.HuaShen_H)
                    {
                        //npc化神
                        gradeName = "huaShen";
                    }

                    else if (gradeLevel == GradeLevel.WuDao_Q || gradeLevel == GradeLevel.WuDao_Z || gradeLevel == GradeLevel.WuDao_H)
                    {
                        //npc悟道
                        gradeName = "wuDao";
                    }

                    else if (gradeLevel == GradeLevel.YuHua_Q || gradeLevel == GradeLevel.YuHua_Z || gradeLevel == GradeLevel.YuHua_H)
                    {
                        //npc羽化
                        gradeName = "yuHua";
                    }
                    else if (gradeLevel == GradeLevel.DengXian_Q || gradeLevel == GradeLevel.DengXian_Z || gradeLevel == GradeLevel.DengXian_H)
                    {
                        //npc登仙
                        gradeName = "dengXian";
                    }
                }
                //获取当前境界资质配置
                if (BaseConfig.aptitudeData.Count > 0)
                {

                    AptitudeData aptitudeData = BaseConfig.aptitudeData.Find(n => n.Id.Equals(gradeName));
                    if (aptitudeData != null)
                    {
                        // 资质调整
                        if (aptitudeData.Enable)
                        {
                            List<NpcAptitude> npcAptitudes = commonUtil.GetNpcAptitudes(unitNPC.data);
                            NpcAptitude aptitude = npcAptitudes[0];
                            WorldUnitDynData worldUnitDyn = unitNPC.data.dynUnitData;
                            int aptitudeNumber = commonUtil.getRandomBetween(aptitudeData);
                            if (aptitude.Aptitude == Aptitude.Dao)
                            {
                                if (worldUnitDyn.basisBlade.lastValue < aptitudeData.Host)
                                {
                                    worldUnitDyn.basisBlade.baseValue = worldUnitDyn.basisBlade.baseValue + (aptitudeData.Host - worldUnitDyn.basisBlade.lastValue);//刀
                                    worldUnitDyn.basisSpear.baseValue = worldUnitDyn.basisSpear.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSpear.lastValue);//枪
                                    worldUnitDyn.basisSword.baseValue = worldUnitDyn.basisSword.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSword.lastValue);//剑
                                    worldUnitDyn.basisFist.baseValue = worldUnitDyn.basisFist.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFist.lastValue);//拳
                                    worldUnitDyn.basisPalm.baseValue = worldUnitDyn.basisPalm.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisPalm.lastValue);//掌
                                    worldUnitDyn.basisFinger.baseValue = worldUnitDyn.basisFinger.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFinger.lastValue);//指
                                    worldUnitDyn.basisFire.baseValue = worldUnitDyn.basisFire.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFire.lastValue);//火
                                    worldUnitDyn.basisFroze.baseValue = worldUnitDyn.basisFroze.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFroze.lastValue);//水
                                    worldUnitDyn.basisThunder.baseValue = worldUnitDyn.basisThunder.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisThunder.lastValue);//雷
                                    worldUnitDyn.basisWind.baseValue = worldUnitDyn.basisWind.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWind.lastValue);//风
                                    worldUnitDyn.basisEarth.baseValue = worldUnitDyn.basisEarth.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisEarth.lastValue);//土
                                    worldUnitDyn.basisWood.baseValue = worldUnitDyn.basisWood.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWood.lastValue);//木
                                }
                            }
                            else if (aptitude.Aptitude == Aptitude.Qiang)
                            {
                                if (worldUnitDyn.basisSpear.lastValue < aptitudeData.Host)
                                {
                                    worldUnitDyn.basisBlade.baseValue = worldUnitDyn.basisBlade.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisBlade.lastValue);//刀
                                    worldUnitDyn.basisSpear.baseValue = worldUnitDyn.basisSpear.baseValue + (aptitudeData.Host - worldUnitDyn.basisSpear.lastValue);//枪
                                    worldUnitDyn.basisSword.baseValue = worldUnitDyn.basisSword.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSword.lastValue);//剑
                                    worldUnitDyn.basisFist.baseValue = worldUnitDyn.basisFist.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFist.lastValue);//拳
                                    worldUnitDyn.basisPalm.baseValue = worldUnitDyn.basisPalm.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisPalm.lastValue);//掌
                                    worldUnitDyn.basisFinger.baseValue = worldUnitDyn.basisFinger.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFinger.lastValue);//指
                                    worldUnitDyn.basisFire.baseValue = worldUnitDyn.basisFire.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFire.lastValue);//火
                                    worldUnitDyn.basisFroze.baseValue = worldUnitDyn.basisFroze.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFroze.lastValue);//水
                                    worldUnitDyn.basisThunder.baseValue = worldUnitDyn.basisThunder.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisThunder.lastValue);//雷
                                    worldUnitDyn.basisWind.baseValue = worldUnitDyn.basisWind.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWind.lastValue);//风
                                    worldUnitDyn.basisEarth.baseValue = worldUnitDyn.basisEarth.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisEarth.lastValue);//土
                                    worldUnitDyn.basisWood.baseValue = worldUnitDyn.basisWood.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWood.lastValue);//木
                                }
                            }
                            else if (aptitude.Aptitude == Aptitude.Jian)
                            {
                                if (worldUnitDyn.basisSword.lastValue < aptitudeData.Host)
                                {
                                    worldUnitDyn.basisBlade.baseValue = worldUnitDyn.basisBlade.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisBlade.lastValue);//刀
                                    worldUnitDyn.basisSpear.baseValue = worldUnitDyn.basisSpear.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSpear.lastValue);//枪
                                    worldUnitDyn.basisSword.baseValue = worldUnitDyn.basisSword.baseValue + (aptitudeData.Host - worldUnitDyn.basisSword.lastValue);//剑
                                    worldUnitDyn.basisFist.baseValue = worldUnitDyn.basisFist.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFist.lastValue);//拳
                                    worldUnitDyn.basisPalm.baseValue = worldUnitDyn.basisPalm.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisPalm.lastValue);//掌
                                    worldUnitDyn.basisFinger.baseValue = worldUnitDyn.basisFinger.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFinger.lastValue);//指
                                    worldUnitDyn.basisFire.baseValue = worldUnitDyn.basisFire.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFire.lastValue);//火
                                    worldUnitDyn.basisFroze.baseValue = worldUnitDyn.basisFroze.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFroze.lastValue);//水
                                    worldUnitDyn.basisThunder.baseValue = worldUnitDyn.basisThunder.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisThunder.lastValue);//雷
                                    worldUnitDyn.basisWind.baseValue = worldUnitDyn.basisWind.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWind.lastValue);//风
                                    worldUnitDyn.basisEarth.baseValue = worldUnitDyn.basisEarth.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisEarth.lastValue);//土
                                    worldUnitDyn.basisWood.baseValue = worldUnitDyn.basisWood.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWood.lastValue);//木
                                }
                            }
                            else if (aptitude.Aptitude == Aptitude.Quan)
                            {
                                if (worldUnitDyn.basisFist.lastValue < aptitudeData.Host)
                                {
                                    worldUnitDyn.basisBlade.baseValue = worldUnitDyn.basisBlade.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisBlade.lastValue);//刀
                                    worldUnitDyn.basisSpear.baseValue = worldUnitDyn.basisSpear.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSpear.lastValue);//枪
                                    worldUnitDyn.basisSword.baseValue = worldUnitDyn.basisSword.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSword.lastValue);//剑
                                    worldUnitDyn.basisFist.baseValue = worldUnitDyn.basisFist.baseValue + (aptitudeData.Host - worldUnitDyn.basisFist.lastValue);//拳
                                    worldUnitDyn.basisPalm.baseValue = worldUnitDyn.basisPalm.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisPalm.lastValue);//掌
                                    worldUnitDyn.basisFinger.baseValue = worldUnitDyn.basisFinger.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFinger.lastValue);//指
                                    worldUnitDyn.basisFire.baseValue = worldUnitDyn.basisFire.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFire.lastValue);//火
                                    worldUnitDyn.basisFroze.baseValue = worldUnitDyn.basisFroze.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFroze.lastValue);//水
                                    worldUnitDyn.basisThunder.baseValue = worldUnitDyn.basisThunder.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisThunder.lastValue);//雷
                                    worldUnitDyn.basisWind.baseValue = worldUnitDyn.basisWind.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWind.lastValue);//风
                                    worldUnitDyn.basisEarth.baseValue = worldUnitDyn.basisEarth.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisEarth.lastValue);//土
                                    worldUnitDyn.basisWood.baseValue = worldUnitDyn.basisWood.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWood.lastValue);//木
                                }
                            }
                            else if (aptitude.Aptitude == Aptitude.Zhang)
                            {
                                if (worldUnitDyn.basisPalm.lastValue < aptitudeData.Host)
                                {
                                    worldUnitDyn.basisBlade.baseValue = worldUnitDyn.basisBlade.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisBlade.lastValue);//刀
                                    worldUnitDyn.basisSpear.baseValue = worldUnitDyn.basisSpear.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSpear.lastValue);//枪
                                    worldUnitDyn.basisSword.baseValue = worldUnitDyn.basisSword.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSword.lastValue);//剑
                                    worldUnitDyn.basisFist.baseValue = worldUnitDyn.basisFist.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFist.lastValue);//拳
                                    worldUnitDyn.basisPalm.baseValue = worldUnitDyn.basisPalm.baseValue + (aptitudeData.Host - worldUnitDyn.basisPalm.lastValue);//掌
                                    worldUnitDyn.basisFinger.baseValue = worldUnitDyn.basisFinger.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFinger.lastValue);//指
                                    worldUnitDyn.basisFire.baseValue = worldUnitDyn.basisFire.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFire.lastValue);//火
                                    worldUnitDyn.basisFroze.baseValue = worldUnitDyn.basisFroze.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFroze.lastValue);//水
                                    worldUnitDyn.basisThunder.baseValue = worldUnitDyn.basisThunder.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisThunder.lastValue);//雷
                                    worldUnitDyn.basisWind.baseValue = worldUnitDyn.basisWind.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWind.lastValue);//风
                                    worldUnitDyn.basisEarth.baseValue = worldUnitDyn.basisEarth.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisEarth.lastValue);//土
                                    worldUnitDyn.basisWood.baseValue = worldUnitDyn.basisWood.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWood.lastValue);//木
                                }
                            }
                            else if (aptitude.Aptitude == Aptitude.Zhi)
                            {
                                if (worldUnitDyn.basisFinger.lastValue < aptitudeData.Host)
                                {
                                    worldUnitDyn.basisBlade.baseValue = worldUnitDyn.basisBlade.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisBlade.lastValue);//刀
                                    worldUnitDyn.basisSpear.baseValue = worldUnitDyn.basisSpear.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSpear.lastValue);//枪
                                    worldUnitDyn.basisSword.baseValue = worldUnitDyn.basisSword.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSword.lastValue);//剑
                                    worldUnitDyn.basisFist.baseValue = worldUnitDyn.basisFist.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFist.lastValue);//拳
                                    worldUnitDyn.basisPalm.baseValue = worldUnitDyn.basisPalm.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisPalm.lastValue);//掌
                                    worldUnitDyn.basisFinger.baseValue = worldUnitDyn.basisFinger.baseValue + (aptitudeData.Host - worldUnitDyn.basisFinger.lastValue);//指
                                    worldUnitDyn.basisFire.baseValue = worldUnitDyn.basisFire.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFire.lastValue);//火
                                    worldUnitDyn.basisFroze.baseValue = worldUnitDyn.basisFroze.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFroze.lastValue);//水
                                    worldUnitDyn.basisThunder.baseValue = worldUnitDyn.basisThunder.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisThunder.lastValue);//雷
                                    worldUnitDyn.basisWind.baseValue = worldUnitDyn.basisWind.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWind.lastValue);//风
                                    worldUnitDyn.basisEarth.baseValue = worldUnitDyn.basisEarth.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisEarth.lastValue);//土
                                    worldUnitDyn.basisWood.baseValue = worldUnitDyn.basisWood.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWood.lastValue);//木
                                }
                            }
                            else if (aptitude.Aptitude == Aptitude.Huo)
                            {
                                if (worldUnitDyn.basisFire.lastValue < aptitudeData.Host)
                                {
                                    worldUnitDyn.basisBlade.baseValue = worldUnitDyn.basisBlade.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisBlade.lastValue);//刀
                                    worldUnitDyn.basisSpear.baseValue = worldUnitDyn.basisSpear.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSpear.lastValue);//枪
                                    worldUnitDyn.basisSword.baseValue = worldUnitDyn.basisSword.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSword.lastValue);//剑
                                    worldUnitDyn.basisFist.baseValue = worldUnitDyn.basisFist.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFist.lastValue);//拳
                                    worldUnitDyn.basisPalm.baseValue = worldUnitDyn.basisPalm.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisPalm.lastValue);//掌
                                    worldUnitDyn.basisFinger.baseValue = worldUnitDyn.basisFinger.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFinger.lastValue);//指
                                    worldUnitDyn.basisFire.baseValue = worldUnitDyn.basisFire.baseValue + (aptitudeData.Host - worldUnitDyn.basisFire.lastValue);//火
                                    worldUnitDyn.basisFroze.baseValue = worldUnitDyn.basisFroze.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFroze.lastValue);//水
                                    worldUnitDyn.basisThunder.baseValue = worldUnitDyn.basisThunder.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisThunder.lastValue);//雷
                                    worldUnitDyn.basisWind.baseValue = worldUnitDyn.basisWind.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWind.lastValue);//风
                                    worldUnitDyn.basisEarth.baseValue = worldUnitDyn.basisEarth.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisEarth.lastValue);//土
                                    worldUnitDyn.basisWood.baseValue = worldUnitDyn.basisWood.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWood.lastValue);//木
                                }
                            }
                            else if (aptitude.Aptitude == Aptitude.Shui)
                            {
                                if (worldUnitDyn.basisFroze.lastValue < aptitudeData.Host)
                                {
                                    worldUnitDyn.basisBlade.baseValue = worldUnitDyn.basisBlade.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisBlade.lastValue);//刀
                                    worldUnitDyn.basisSpear.baseValue = worldUnitDyn.basisSpear.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSpear.lastValue);//枪
                                    worldUnitDyn.basisSword.baseValue = worldUnitDyn.basisSword.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSword.lastValue);//剑
                                    worldUnitDyn.basisFist.baseValue = worldUnitDyn.basisFist.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFist.lastValue);//拳
                                    worldUnitDyn.basisPalm.baseValue = worldUnitDyn.basisPalm.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisPalm.lastValue);//掌
                                    worldUnitDyn.basisFinger.baseValue = worldUnitDyn.basisFinger.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFinger.lastValue);//指
                                    worldUnitDyn.basisFire.baseValue = worldUnitDyn.basisFire.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFire.lastValue);//火
                                    worldUnitDyn.basisFroze.baseValue = worldUnitDyn.basisFroze.baseValue + (aptitudeData.Host - worldUnitDyn.basisFroze.lastValue);//水
                                    worldUnitDyn.basisThunder.baseValue = worldUnitDyn.basisThunder.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisThunder.lastValue);//雷
                                    worldUnitDyn.basisWind.baseValue = worldUnitDyn.basisWind.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWind.lastValue);//风
                                    worldUnitDyn.basisEarth.baseValue = worldUnitDyn.basisEarth.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisEarth.lastValue);//土
                                    worldUnitDyn.basisWood.baseValue = worldUnitDyn.basisWood.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWood.lastValue);//木
                                }
                            }
                            else if (aptitude.Aptitude == Aptitude.Lei)
                            {
                                if (worldUnitDyn.basisThunder.lastValue < aptitudeData.Host)
                                {
                                    worldUnitDyn.basisBlade.baseValue = worldUnitDyn.basisBlade.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisBlade.lastValue);//刀
                                    worldUnitDyn.basisSpear.baseValue = worldUnitDyn.basisSpear.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSpear.lastValue);//枪
                                    worldUnitDyn.basisSword.baseValue = worldUnitDyn.basisSword.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSword.lastValue);//剑
                                    worldUnitDyn.basisFist.baseValue = worldUnitDyn.basisFist.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFist.lastValue);//拳
                                    worldUnitDyn.basisPalm.baseValue = worldUnitDyn.basisPalm.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisPalm.lastValue);//掌
                                    worldUnitDyn.basisFinger.baseValue = worldUnitDyn.basisFinger.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFinger.lastValue);//指
                                    worldUnitDyn.basisFire.baseValue = worldUnitDyn.basisFire.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFire.lastValue);//火
                                    worldUnitDyn.basisFroze.baseValue = worldUnitDyn.basisFroze.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFroze.lastValue);//水
                                    worldUnitDyn.basisThunder.baseValue = worldUnitDyn.basisThunder.baseValue + (aptitudeData.Host - worldUnitDyn.basisThunder.lastValue);//雷
                                    worldUnitDyn.basisWind.baseValue = worldUnitDyn.basisWind.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWind.lastValue);//风
                                    worldUnitDyn.basisEarth.baseValue = worldUnitDyn.basisEarth.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisEarth.lastValue);//土
                                    worldUnitDyn.basisWood.baseValue = worldUnitDyn.basisWood.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWood.lastValue);//木
                                }
                            }
                            else if (aptitude.Aptitude == Aptitude.Feng)
                            {
                                if (worldUnitDyn.basisWind.lastValue < aptitudeData.Host)
                                {
                                    worldUnitDyn.basisBlade.baseValue = worldUnitDyn.basisBlade.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisBlade.lastValue);//刀
                                    worldUnitDyn.basisSpear.baseValue = worldUnitDyn.basisSpear.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSpear.lastValue);//枪
                                    worldUnitDyn.basisSword.baseValue = worldUnitDyn.basisSword.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSword.lastValue);//剑
                                    worldUnitDyn.basisFist.baseValue = worldUnitDyn.basisFist.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFist.lastValue);//拳
                                    worldUnitDyn.basisPalm.baseValue = worldUnitDyn.basisPalm.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisPalm.lastValue);//掌
                                    worldUnitDyn.basisFinger.baseValue = worldUnitDyn.basisFinger.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFinger.lastValue);//指
                                    worldUnitDyn.basisFire.baseValue = worldUnitDyn.basisFire.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFire.lastValue);//火
                                    worldUnitDyn.basisFroze.baseValue = worldUnitDyn.basisFroze.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFroze.lastValue);//水
                                    worldUnitDyn.basisThunder.baseValue = worldUnitDyn.basisThunder.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisThunder.lastValue);//雷
                                    worldUnitDyn.basisWind.baseValue = worldUnitDyn.basisWind.baseValue + (aptitudeData.Host - worldUnitDyn.basisWind.lastValue);//风
                                    worldUnitDyn.basisEarth.baseValue = worldUnitDyn.basisEarth.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisEarth.lastValue);//土
                                    worldUnitDyn.basisWood.baseValue = worldUnitDyn.basisWood.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWood.lastValue);//木
                                }
                            }
                            else if (aptitude.Aptitude == Aptitude.Tu)
                            {
                                if (worldUnitDyn.basisEarth.lastValue < aptitudeData.Host)
                                {
                                    worldUnitDyn.basisBlade.baseValue = worldUnitDyn.basisBlade.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisBlade.lastValue);//刀
                                    worldUnitDyn.basisSpear.baseValue = worldUnitDyn.basisSpear.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSpear.lastValue);//枪
                                    worldUnitDyn.basisSword.baseValue = worldUnitDyn.basisSword.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSword.lastValue);//剑
                                    worldUnitDyn.basisFist.baseValue = worldUnitDyn.basisFist.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFist.lastValue);//拳
                                    worldUnitDyn.basisPalm.baseValue = worldUnitDyn.basisPalm.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisPalm.lastValue);//掌
                                    worldUnitDyn.basisFinger.baseValue = worldUnitDyn.basisFinger.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFinger.lastValue);//指
                                    worldUnitDyn.basisFire.baseValue = worldUnitDyn.basisFire.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFire.lastValue);//火
                                    worldUnitDyn.basisFroze.baseValue = worldUnitDyn.basisFroze.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFroze.lastValue);//水
                                    worldUnitDyn.basisThunder.baseValue = worldUnitDyn.basisThunder.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisThunder.lastValue);//雷
                                    worldUnitDyn.basisWind.baseValue = worldUnitDyn.basisWind.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWind.lastValue);//风
                                    worldUnitDyn.basisEarth.baseValue = worldUnitDyn.basisEarth.baseValue + (aptitudeData.Host - worldUnitDyn.basisEarth.lastValue);//土
                                    worldUnitDyn.basisWood.baseValue = worldUnitDyn.basisWood.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWood.lastValue);//木
                                }
                            }
                            else if (aptitude.Aptitude == Aptitude.Mu)
                            {
                                if (worldUnitDyn.basisWood.lastValue < aptitudeData.Host)
                                {
                                    worldUnitDyn.basisBlade.baseValue = worldUnitDyn.basisBlade.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisBlade.lastValue);//刀
                                    worldUnitDyn.basisSpear.baseValue = worldUnitDyn.basisSpear.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSpear.lastValue);//枪
                                    worldUnitDyn.basisSword.baseValue = worldUnitDyn.basisSword.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisSword.lastValue);//剑
                                    worldUnitDyn.basisFist.baseValue = worldUnitDyn.basisFist.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFist.lastValue);//拳
                                    worldUnitDyn.basisPalm.baseValue = worldUnitDyn.basisPalm.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisPalm.lastValue);//掌
                                    worldUnitDyn.basisFinger.baseValue = worldUnitDyn.basisFinger.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFinger.lastValue);//指
                                    worldUnitDyn.basisFire.baseValue = worldUnitDyn.basisFire.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFire.lastValue);//火
                                    worldUnitDyn.basisFroze.baseValue = worldUnitDyn.basisFroze.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisFroze.lastValue);//水
                                    worldUnitDyn.basisThunder.baseValue = worldUnitDyn.basisThunder.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisThunder.lastValue);//雷
                                    worldUnitDyn.basisWind.baseValue = worldUnitDyn.basisWind.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisWind.lastValue);//风
                                    worldUnitDyn.basisEarth.baseValue = worldUnitDyn.basisEarth.baseValue + (commonUtil.getRandomBetween(aptitudeData) - worldUnitDyn.basisEarth.lastValue);//土
                                    worldUnitDyn.basisWood.baseValue = worldUnitDyn.basisWood.baseValue + (aptitudeData.Host - worldUnitDyn.basisWood.lastValue);//木
                                }
                            }
                        }
                    }
                }

                // 发放福利
                if (BaseConfig.isSendWelfare)
                {
                    //获取当前月份，及判断是否满足发放时间DataWorld.World
                    DataWorld.World world = g.data.world;
                    int currentMonth = world.GetDates()[1];
                    //string date = JsonConvert.SerializeObject(world.GetDates());// 年 月 日
                    if (BaseConfig.sendWelfareMonth.Contains(currentMonth))
                    {
                        //LogUtil.Log("太阳球MOD", "当前月份为：" + currentMonth + " 满足发放时间");
                        List<ItemModel> welfareIds = new List<ItemModel>();
                        if (gradeName.Equals("lianQi"))
                        {
                            //npc练气福利
                            welfareIds = BaseConfig.lianQi_Welfare;
                        }

                        else if (gradeName.Equals("zhuJi"))
                        {
                            //npc筑基福利
                            welfareIds = BaseConfig.zhuJi_Welfare;

                        }
                        else if (gradeName.Equals("jieJing"))
                        {
                            //npc结晶福利
                            welfareIds = BaseConfig.jieJing_Welfare;

                        }
                        else if (gradeName.Equals("jinDan"))
                        {
                            //npc金丹福利
                            welfareIds = BaseConfig.jinDan_Welfare;

                        }
                        else if (gradeName.Equals("juLing"))
                        {
                            //npc具灵福利
                            welfareIds = BaseConfig.juLing_Welfare;
                        }
                        else if (gradeName.Equals("yuanYing"))
                        {
                            //npc元婴福利
                            welfareIds = BaseConfig.yuanYing_Welfare;
                        }
                        else if (gradeName.Equals("huaShen"))
                        {
                            //npc化神福利
                            welfareIds = BaseConfig.huaShen_Welfare;
                        }

                        else if (gradeName.Equals("wuDao"))
                        {
                            //npc悟道福利
                            welfareIds = BaseConfig.wuDao_Welfare;
                        }

                        else if (gradeName.Equals("yuHua"))
                        {
                            //npc羽化福利
                            welfareIds = BaseConfig.yuHua_Welfare;
                        }
                        else if (gradeName.Equals("dengXian"))
                        {
                            //npc登仙福利
                            welfareIds = BaseConfig.dengXian_Welfare;
                        }

                        //配置物品
                        Il2CppSystem.Collections.Generic.List<DataProps.PropsData> propsDatas = new Il2CppSystem.Collections.Generic.List<DataProps.PropsData>();
                        List<string> itemNames = new List<string>();
                        foreach (ItemModel itemModel in welfareIds)
                        {
                            DataProps.PropsData props = new DataProps.PropsData();
                            props.propsCount = itemModel.Count;
                            props.propsID = itemModel.Id;
                            props.propsType = DataProps.PropsDataType.Props;
                            propsDatas.Add(props);
                            itemNames.Add(string.Format("【{0}：{1}】", itemModel.Name, itemModel.Count));
                        }
                        if (propsDatas.Count > 0)
                        {
                            //添加物品
                            //判断npc剩余背包格子数量
                            int oldCount = unitNPC.data.unitData.propData.GetGridCurNum(false); ;
                            int spareCount = unitNPC.data.dynUnitData.propGridNum.value - oldCount;
                            if (spareCount < propsDatas.Count)
                            {
                                //如果格子不够销毁低价值物品
                                unitNPC.data.CostItemCountLowWorth(propsDatas.Count - spareCount);
                            }
                            //LogUtil.Log("太阳球MOD", "发放人员【" + relation + "】：" + npcRealName);
                            //LogUtil.Log("太阳球MOD", "发放福利：" + JsonConvert.SerializeObject(itemNames));
                            foreach (DataProps.PropsData item in propsDatas)
                            {
                                unitNPC.data.RewardPropItem(item.propsID, item.propsCount, false);
                            }
                        }
                    }
                    else
                    {
                        //LogUtil.Log("太阳球MOD", "当前月份为：" + currentMonth + " 不满足发放时间");
                    }
                    //LogUtil.Log("太阳球MOD", "发放完毕");
                }
                //学习技能
                if (BaseConfig.isStudyMartial)
                {
                    //获取Npc资质
                    List<NpcAptitude> npcAptitudes = commonUtil.GetNpcAptitudes(unitNPC.data);
                    //判断npc技能等级跟境界是否符合
                    int gradeId = unitNPC.data.dynUnitData.GetGrade();
                    NpcAptitude aptitude = npcAptitudes[0];
                    //LogUtil.Log("太阳球MOD", "武灵");
                    //武灵
                    if (true)
                    {
                        string killId = unitNPC.data.unitData.skillLeft;
                        if (killId.Equals(""))
                        {
                            Il2CppSystem.Collections.Generic.List<DataProps.PropsData> goodDatas = commonUtil.GetGoodMartial(martialProps, aptitude.Aptitude, MartialType.SkillLeft, gradeId);
                            if (goodDatas.Count > 0)
                            {
                                System.Random random = new System.Random();
                                int index = random.Next(0, goodDatas.Count - 1);
                                DataProps.PropsData propsData = goodDatas[index].Clone();
                                unitNPC.data.unitData.StudyActionMartialProp(propsData);
                                unitNPC.data.unitData.skillLeft = propsData.soleID;
                                //LogUtil.Log("太阳球MOD", "学习武灵：" + propsData.propsInfoBase.name);
                            }
                        }
                        else
                        {
                            DataProps.PropsData martialData = unitNPC.data.unitData.GetActionMartial(killId).data;
                            int martialGade = martialData.propsInfoBase.grade;
                            //判断是否有当前境界武学、比较是不是红色功法
                            if (gradeId > martialGade || martialData.propsInfoBase.level != 6)
                            {
                                Il2CppSystem.Collections.Generic.List<DataProps.PropsData> goodDatas = commonUtil.GetGoodMartial(martialProps, aptitude.Aptitude, MartialType.SkillLeft, gradeId);
                                if (goodDatas.Count > 0)
                                {
                                    System.Random random = new System.Random();
                                    int index = random.Next(0, goodDatas.Count - 1);
                                    DataProps.PropsData propsData = goodDatas[index].Clone();
                                    unitNPC.data.unitData.StudyActionMartialProp(propsData);
                                    unitNPC.data.unitData.skillLeft = propsData.soleID;
                                    //LogUtil.Log("太阳球MOD", "学习武灵：" + propsData.propsInfoBase.name);
                                }
                            }
                        }

                    }
                    //LogUtil.Log("太阳球MOD", "绝技");
                    //绝技
                    if (true)
                    {
                        string killId = unitNPC.data.unitData.skillRight;

                        if (killId.Equals(""))
                        {
                            Il2CppSystem.Collections.Generic.List<DataProps.PropsData> goodDatas = commonUtil.GetGoodMartial(martialProps, aptitude.Aptitude, MartialType.SkillRight, gradeId);
                            if (goodDatas.Count > 0)
                            {
                                System.Random random = new System.Random();
                                int index = random.Next(0, goodDatas.Count - 1);
                                DataProps.PropsData propsData = goodDatas[index].Clone();
                                unitNPC.data.unitData.StudyActionMartialProp(propsData);
                                unitNPC.data.unitData.skillRight = propsData.soleID;
                                //LogUtil.Log("太阳球MOD", "学习绝技：" + propsData.propsInfoBase.name);
                            }
                        }
                        else
                        {
                            DataProps.PropsData martialData = unitNPC.data.unitData.GetActionMartial(killId).data;
                            int martialGade = martialData.propsInfoBase.grade;
                            //判断是否有当前境界武学、比较是不是红色功法
                            if (gradeId > martialGade || martialData.propsInfoBase.level != 6)
                            {
                                Il2CppSystem.Collections.Generic.List<DataProps.PropsData> goodDatas = commonUtil.GetGoodMartial(martialProps, aptitude.Aptitude, MartialType.SkillRight, gradeId);
                                if (goodDatas.Count > 0)
                                {
                                    System.Random random = new System.Random();
                                    int index = random.Next(0, goodDatas.Count - 1);
                                    DataProps.PropsData propsData = goodDatas[index].Clone();
                                    unitNPC.data.unitData.StudyActionMartialProp(propsData);
                                    unitNPC.data.unitData.skillRight = propsData.soleID;
                                    //LogUtil.Log("太阳球MOD", "学习绝技：" + propsData.propsInfoBase.name);
                                }
                            }
                        }

                    }
                    //LogUtil.Log("太阳球MOD", "身法");
                    //身法
                    if (true)
                    {
                        string killId = unitNPC.data.unitData.step;
                        if (killId.Equals(""))
                        {
                            Il2CppSystem.Collections.Generic.List<DataProps.PropsData> goodDatas = commonUtil.GetGoodMartial(martialProps, aptitude.Aptitude, MartialType.Step, gradeId);
                            if (goodDatas.Count > 0)
                            {
                                System.Random random = new System.Random();
                                int index = random.Next(0, goodDatas.Count - 1);
                                DataProps.PropsData propsData = goodDatas[index].Clone();
                                unitNPC.data.unitData.StudyActionMartialProp(propsData);
                                unitNPC.data.unitData.step = propsData.soleID;
                                //LogUtil.Log("太阳球MOD", "学习身法：" + propsData.propsInfoBase.name);
                            }
                        }
                        else
                        {
                            DataProps.PropsData martialData = unitNPC.data.unitData.GetActionMartial(killId).data;
                            int martialGade = martialData.propsInfoBase.grade;
                            //判断是否有当前境界武学、比较是不是红色功法
                            if (gradeId > martialGade || martialData.propsInfoBase.level != 6)
                            {
                                Il2CppSystem.Collections.Generic.List<DataProps.PropsData> goodDatas = commonUtil.GetGoodMartial(martialProps, aptitude.Aptitude, MartialType.Step, gradeId);
                                if (goodDatas.Count > 0)
                                {
                                    System.Random random = new System.Random();
                                    int index = random.Next(0, goodDatas.Count - 1);
                                    DataProps.PropsData propsData = goodDatas[index].Clone();
                                    unitNPC.data.unitData.StudyActionMartialProp(propsData);
                                    unitNPC.data.unitData.step = propsData.soleID;
                                    //LogUtil.Log("太阳球MOD", "学习身法：" + propsData.propsInfoBase.name);
                                }
                            }
                        }

                    }
                    //LogUtil.Log("太阳球MOD", "心法");
                    //心法
                    if (true)
                    {
                        bool isChange = false;
                        int[] heardTypes = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
                        string[] killIds = unitNPC.data.unitData.abilitys;
                        List<string> nowAbilitys = new List<string>();
                        List<DataProps.PropsData> heardProps = new List<DataProps.PropsData>();
                        foreach (string killId in killIds)
                        {
                            if (!killId.Equals(""))
                            {
                                DataProps.PropsData martialData = unitNPC.data.unitData.GetActionMartial(killId).data;
                                heardProps.Add(martialData);
                                nowAbilitys.Add(killId);
                            }

                        }
                        foreach (int heardType in heardTypes)
                        {

                            List<DataProps.PropsData> currentDatas = new List<DataProps.PropsData>();
                            if (heardProps.Count > 0)
                            {
                                List<DataProps.PropsData> select = heardProps.FindAll(e =>
                                {
                                    ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                                    if (baseItem.type == heardType)
                                    {
                                        return true;
                                    }
                                    else
                                    {
                                        return false;
                                    }
                                });
                                currentDatas.AddRange(select);
                            }
                            if (currentDatas.Count > 0)
                            {
                                DataProps.PropsData currentData = currentDatas[0];
                                int martialGade = currentData.propsInfoBase.grade;
                                //判断境界
                                if (gradeId > martialGade || currentData.propsInfoBase.level != 6)
                                {
                                    Il2CppSystem.Collections.Generic.List<DataProps.PropsData> goodDatas = commonUtil.GetGoodMental(martialProps, aptitude.Aptitude, MartialType.Ability, gradeId, heardType);
                                    if (goodDatas.Count > 0)
                                    {
                                        System.Random random = new System.Random();
                                        int index = random.Next(0, goodDatas.Count - 1);
                                        DataProps.PropsData propsData = goodDatas[index].Clone();
                                        unitNPC.data.unitData.StudyActionMartialProp(propsData);
                                        nowAbilitys.Remove(currentData.soleID);
                                        nowAbilitys.Add(propsData.soleID);
                                        isChange = true;
                                        //LogUtil.Log("太阳球MOD", "学习心法：" + propsData.propsInfoBase.name);
                                    }
                                }
                            }
                            else
                            {
                                Il2CppSystem.Collections.Generic.List<DataProps.PropsData> goodDatas = commonUtil.GetGoodMental(martialProps, aptitude.Aptitude, MartialType.Ability, gradeId, heardType);
                                if (goodDatas.Count > 0)
                                {
                                    System.Random random = new System.Random();
                                    int index = random.Next(0, goodDatas.Count - 1);
                                    DataProps.PropsData propsData = goodDatas[index].Clone();
                                    unitNPC.data.unitData.StudyActionMartialProp(propsData);
                                    nowAbilitys.Add(propsData.soleID);
                                    isChange = true;
                                    //LogUtil.Log("太阳球MOD", "学习心法：" + propsData.propsInfoBase.name);
                                }

                            }
                        }

                        //更改心法
                        if (isChange)
                        {
                            if (nowAbilitys.Count == 1)
                            {
                                nowAbilitys.AddRange(new string[] { "", "", "", "", "", "", "" });
                            }
                            else if (nowAbilitys.Count == 2)
                            {
                                nowAbilitys.AddRange(new string[] { "", "", "", "", "", "" });
                            }
                            else if (nowAbilitys.Count == 3)
                            {
                                nowAbilitys.AddRange(new string[] { "", "", "", "", "" });
                            }
                            else if (nowAbilitys.Count == 4)
                            {
                                nowAbilitys.AddRange(new string[] { "", "", "", "" });
                            }
                            else if (nowAbilitys.Count == 5)
                            {
                                nowAbilitys.AddRange(new string[] { "", "", "" });
                            }
                            else if (nowAbilitys.Count == 6)
                            {
                                nowAbilitys.AddRange(new string[] { "", "" });
                            }
                            else if (nowAbilitys.Count == 7)
                            {
                                nowAbilitys.AddRange(new string[] { "" });
                            }
                            unitNPC.data.unitData.abilitys = nowAbilitys.ToArray();
                        }

                    }
                    //LogUtil.Log("太阳球MOD", "神通");
                    //神通
                    if (true)
                    {
                        string killId = unitNPC.data.unitData.ultimate;
                        if (killId.Equals(""))
                        {
                            Il2CppSystem.Collections.Generic.List<DataProps.PropsData> goodDatas = commonUtil.GetGoodMartial(martialProps, aptitude.Aptitude, MartialType.Ultimate, gradeId);
                            if (goodDatas.Count > 0)
                            {
                                System.Random random = new System.Random();
                                int index = random.Next(0, goodDatas.Count - 1);
                                DataProps.PropsData propsData = goodDatas[index].Clone();
                                unitNPC.data.unitData.StudyActionMartialProp(propsData);
                                unitNPC.data.unitData.ultimate = propsData.soleID;
                                //LogUtil.Log("太阳球MOD", "学习神通：" + propsData.propsInfoBase.name);
                            }
                        }
                        else
                        {
                            DataProps.PropsData martialData = unitNPC.data.unitData.GetActionMartial(killId).data;
                            int martialGade = martialData.propsInfoBase.grade;
                            //判断是否有当前境界武学、比较是不是红色功法
                            if (gradeId > martialGade || martialData.propsInfoBase.level != 6)
                            {
                                Il2CppSystem.Collections.Generic.List<DataProps.PropsData> goodDatas = commonUtil.GetGoodMartial(martialProps, aptitude.Aptitude, MartialType.Ultimate, gradeId);
                                if (goodDatas.Count > 0)
                                {
                                    System.Random random = new System.Random();
                                    int index = random.Next(0, goodDatas.Count - 1);
                                    DataProps.PropsData propsData = goodDatas[index].Clone();
                                    unitNPC.data.unitData.StudyActionMartialProp(propsData);
                                    unitNPC.data.unitData.ultimate = propsData.soleID;
                                    //LogUtil.Log("太阳球MOD", "学习神通：" + propsData.propsInfoBase.name);
                                }
                            }
                        }

                    }
                }
                //发放突破物资
                if (true)
                {
                    //是否必须低于我的境界
                    if (BaseConfig.isLowGrade)
                    {
                        if (Convert.ToInt32(myLevel) <= Convert.ToInt32(gradeLevel))
                        {
                            //LogUtil.Log("太阳球MOD", string.Format("境界比较：【{0}】的境界大于等于我当前境界", npcRealName));
                            return;
                        }
                    }
                    //判断npc职位及所在宗门的所在州
                    if (!schoolName.Equals(""))
                    {
                        if (relation.Equals("宗门大长老"))
                        {
                            AreaConfig areaConfig = BaseConfig.school.DaZhangLaoArea.Find(n => n.SchoolName.Contains(schoolName));
                            if (areaConfig != null)
                            {
                                //是否启用区域物资限制
                                if (areaConfig.Enable)
                                {
                                    // 如果当前境界大于发放境界则不发放突破物资
                                    if (Convert.ToInt32(gradeLevel) > areaConfig.Level)
                                    {
                                        //LogUtil.Log("太阳球MOD", string.Format("【{0}】 不满足区域宗门【{1}】的发放境界【{2}】条件", npcRealName, schoolName, areaConfig.Level));
                                        return;
                                    }
                                }
                            }
                        }
                        if (relation.Equals("宗门长老"))
                        {
                            AreaConfig areaConfig = BaseConfig.school.ZhangLaoArea.Find(n => n.SchoolName.Contains(schoolName));
                            if (areaConfig != null)
                            {
                                //是否启用区域物资限制
                                if (areaConfig.Enable)
                                {
                                    // 如果当前境界大于发放境界则不发放突破物资
                                    if (Convert.ToInt32(gradeLevel) > areaConfig.Level)
                                    {
                                        //LogUtil.Log("太阳球MOD", string.Format("{0}】 不满足区域宗门【{1}】的发放境界【{2}】条件", npcRealName, schoolName, areaConfig.Level));
                                        return;
                                    }
                                }
                            }
                        }
                        if (relation.Equals("真传弟子"))
                        {
                            AreaConfig areaConfig = BaseConfig.school.ZhenChuanArea.Find(n => n.SchoolName.Contains(schoolName));
                            if (areaConfig != null)
                            {
                                //是否启用区域物资限制
                                if (areaConfig.Enable)
                                {
                                    // 如果当前境界大于发放境界则不发放突破物资
                                    if (Convert.ToInt32(gradeLevel) > areaConfig.Level)
                                    {
                                        //LogUtil.Log("太阳球MOD", string.Format("【{0}】 不满足区域宗门【{1}】的发放境界【{2}】条件", npcRealName, schoolName, areaConfig.Level));
                                        return;
                                    }
                                }
                            }
                        }
                        if (relation.Equals("内门弟子"))
                        {
                            AreaConfig areaConfig = BaseConfig.school.NeiMenArea.Find(n => n.SchoolName.Contains(schoolName));
                            if (areaConfig != null)
                            {
                                //是否启用区域物资限制
                                if (areaConfig.Enable)
                                {
                                    // 如果当前境界大于发放境界则不发放突破物资
                                    if (Convert.ToInt32(gradeLevel) > areaConfig.Level)
                                    {
                                        //LogUtil.Log("太阳球MOD", string.Format("【{0}】 不满足区域宗门【{1}】的发放境界【{2}】条件", npcRealName, schoolName, areaConfig.Level));
                                        return;
                                    }
                                }
                            }
                        }
                        if (relation.Equals("外门弟子"))
                        {
                            AreaConfig areaConfig = BaseConfig.school.WaiMenArea.Find(n => n.SchoolName.Contains(schoolName));
                            if (areaConfig != null)
                            {
                                //是否启用区域物资限制
                                if (areaConfig.Enable)
                                {
                                    // 如果当前境界大于发放境界则不发放突破物资
                                    if (Convert.ToInt32(gradeLevel) > areaConfig.Level)
                                    {
                                        //LogUtil.Log("太阳球MOD", string.Format("【{0}】 不满足区域宗门【{1}】的发放境界【{2}】条件", npcRealName, schoolName, areaConfig.Level));
                                        return;
                                    }
                                }
                            }
                        }
                    }

                    //随机性判断
                    System.Random random = new System.Random();
                    int randomNumber = random.Next(1, 100);
                    if (BaseConfig.probability < randomNumber)
                    {
                        return;
                    }
                    //瓶颈气运
                    bool isLock = commonUtil.HasLockLuck(unitNPC);
                    //发放物品
                    //添加物品
                    List<ItemModel> itemsIds = new List<ItemModel>();
                    //如果存在瓶颈
                    if (isLock)
                    {
                        Il2CppSystem.Collections.Generic.List<DataProps.PropsData> oldDatas = unitNPC.data.unitData.propData.allProps;
                        if (gradeLevel == GradeLevel.LianQi_Q)
                        {
                            //npc练气前期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.lianQi_Q_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.LianQi_Z)
                        {
                            //npc练气中期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.lianQi_Z_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.ZhuJi_Q)
                        {
                            //npc筑基前期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.zhuJi_Q_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.ZhuJi_Z)
                        {
                            //npc筑基中期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.zhuJi_Z_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.JieJing_Q)
                        {
                            //npc结晶前期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.jieJing_Q_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.JieJing_Z)
                        {
                            //npc结晶中期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.jieJing_Z_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.JinDan_Q)
                        {
                            //npc金丹前期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.jinDan_Q_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.JinDan_Z)
                        {
                            //npc金丹中期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.jinDan_Z_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.JuLing_Q)
                        {
                            //npc具灵前期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.juLing_Q_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.JuLing_Z)
                        {
                            //npc具灵中期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.juLing_Z_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.YuanYing_Q)
                        {
                            //npc元婴前期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.yuanYing_Q_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.YuanYing_Z)
                        {
                            //npc元婴中期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.yuanYing_Z_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.HuaShen_Q)
                        {
                            //npc化神前期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.huaShen_Q_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.HuaShen_Z)
                        {
                            //npc化神中期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.huaShen_Z_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.WuDao_Q)
                        {
                            //npc悟道前期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.wuDao_Q_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.WuDao_Z)
                        {
                            //npc悟道中期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.wuDao_Z_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.YuHua_Q)
                        {
                            //npc羽化前期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.yuHua_Q_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.YuHua_Z)
                        {
                            //npc羽化中期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.yuHua_Z_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.DengXian_Q)
                        {
                            //npc登仙前期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.dengXian_Q_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.DengXian_Z)
                        {
                            //npc登仙中期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.dengXian_Z_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        //配置物品
                        Il2CppSystem.Collections.Generic.List<DataProps.PropsData> propsDatas = new Il2CppSystem.Collections.Generic.List<DataProps.PropsData>();
                        List<string> itemNames = new List<string>();
                        foreach (ItemModel itemModel in itemsIds)
                        {
                            DataProps.PropsData props = new DataProps.PropsData();
                            props.propsCount = itemModel.Count;
                            props.propsID = itemModel.Id;
                            props.propsType = DataProps.PropsDataType.Props;
                            propsDatas.Add(props);
                            itemNames.Add(itemModel.Name);
                        }
                        if (propsDatas.Count > 0)
                        {
                            //添加物品
                            //判断npc剩余背包格子数量
                            int oldCount = unitNPC.data.unitData.propData.GetGridCurNum(false); ;
                            int spareCount = unitNPC.data.dynUnitData.propGridNum.value - oldCount;
                            if (spareCount < propsDatas.Count)
                            {
                                //如果格子不够销毁低价值物品
                                unitNPC.data.CostItemCountLowWorth(propsDatas.Count - spareCount);
                            }
                            //LogUtil.Log("太阳球MOD", "发放人员【" + relation + "】：" + npcRealName);
                            //LogUtil.Log("太阳球MOD", "发放物品：" + JsonConvert.SerializeObject(itemNames));
                            foreach (DataProps.PropsData item in propsDatas)
                            {
                                unitNPC.data.RewardPropItem(item.propsID, item.propsCount, false);
                            }

                            //LogUtil.Log("太阳球MOD", "发放结束");
                        }

                    }
                    else
                    {
                        Il2CppSystem.Collections.Generic.List<DataProps.PropsData> oldDatas = unitNPC.data.unitData.propData.allProps;
                        //后期没有气运瓶颈
                        if (gradeLevel == GradeLevel.LianQi_H)
                        {
                            //npc练气后期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.lianQi_H_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.ZhuJi_H)
                        {
                            //npc筑基后期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.zhuJi_H_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.JieJing_H)
                        {
                            //npc结晶后期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.jieJing_H_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.JinDan_H)
                        {
                            //npc金丹后期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.jinDan_H_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.JuLing_H)
                        {
                            //npc具灵后期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.juLing_H_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }

                        else if (gradeLevel == GradeLevel.YuanYing_H)
                        {
                            //npc元婴后期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.yuanYing_H_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.HuaShen_H)
                        {
                            //npc化神后期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.huaShen_H_Yes)
                            {
                                //判断是不是道魂 是的话数量要大于3
                                if (itemModel.Id == BaseConfig.daoHunId)
                                {
                                    int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == BaseConfig.daoHunId; })).Count;
                                    if (existCount < 3)
                                    {
                                        itemsIds.Add(itemModel);
                                    }
                                }
                                else
                                {
                                    int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                    if (existCount == 0)
                                    {
                                        itemsIds.Add(itemModel);
                                    }
                                }

                            }
                        }
                        else if (gradeLevel == GradeLevel.WuDao_H)
                        {
                            //npc悟道后期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.wuDao_H_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        else if (gradeLevel == GradeLevel.YuHua_H)
                        {
                            //npc羽化后期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.yuHua_H_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }

                        else if (gradeLevel == GradeLevel.DengXian_H)
                        {
                            //npc登仙后期添加升级物品
                            //判断是否包含道具
                            foreach (ItemModel itemModel in BaseConfig.dengXian_H_Yes)
                            {
                                int existCount = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == itemModel.Id; })).Count;
                                if (existCount == 0)
                                {
                                    itemsIds.Add(itemModel);
                                }
                            }
                        }
                        //配置物品
                        Il2CppSystem.Collections.Generic.List<DataProps.PropsData> propsDatas = new Il2CppSystem.Collections.Generic.List<DataProps.PropsData>();
                        List<string> itemNames = new List<string>();
                        foreach (ItemModel itemModel in itemsIds)
                        {
                            DataProps.PropsData props = new DataProps.PropsData();
                            props.propsCount = itemModel.Count;
                            props.propsID = itemModel.Id;
                            props.propsType = DataProps.PropsDataType.Props;
                            propsDatas.Add(props);
                            itemNames.Add(itemModel.Name);
                        }
                        if (propsDatas.Count > 0)
                        {
                            //添加物品
                            //判断npc剩余背包格子数量
                            int oldCount = unitNPC.data.unitData.propData.GetGridCurNum(false); ;
                            int spareCount = unitNPC.data.dynUnitData.propGridNum.value - oldCount;
                            if (spareCount < propsDatas.Count)
                            {
                                //如果格子不够销毁低价值物品
                                unitNPC.data.CostItemCountLowWorth(propsDatas.Count - spareCount);
                            }
                            //LogUtil.Log("太阳球MOD", "发放人员【" + relation + "】：" + npcRealName);
                            //LogUtil.Log("太阳球MOD", "发放物品：" + JsonConvert.SerializeObject(itemNames));
                            foreach (DataProps.PropsData item in propsDatas)
                            {
                                //化神之气自定义
                                if (item.propsID == BaseConfig.huaShenZhiQi.Id)
                                {
                                    DataProps.PropsData data = DataProps.PropsData.NewProps(BaseConfig.huaShenZhiQi.Id, 1);
                                    UnhollowerBaseLib.Il2CppStructArray<int> array = data.values;
                                    array[0] = 1;
                                    array[1] = BaseConfig.huaShenZhiQi.Id;
                                    array[2] = 1;
                                    array[3] = BaseConfig.huaShenZhiQi.Attack;
                                    array[4] = BaseConfig.huaShenZhiQi.Defense;
                                    array[5] = BaseConfig.huaShenZhiQi.Strength;
                                    array[6] = BaseConfig.huaShenZhiQi.Psychic;
                                    array[7] = BaseConfig.huaShenZhiQi.Mind;
                                    data.values = array;
                                    unitNPC.data.RewardPropItem(data, false);
                                }
                                // 道魂复制
                                else if (item.propsID == BaseConfig.daoHunId)
                                {
                                    //获取玩家道魂道具
                                    Il2CppSystem.Collections.Generic.List<DataProps.PropsData> userDatas = g.world.playerUnit.data.unitData.propData.allProps;
                                    Il2CppSystem.Collections.Generic.List<DataProps.PropsData> daoHunData = userDatas.FindAll(new Func<DataProps.PropsData, bool>((e) => { return e.propsID == BaseConfig.daoHunId; }));
                                    if (daoHunData.Count > 0)
                                    {
                                        //获取Npc资质
                                        List<NpcAptitude> npcAptitudes = commonUtil.GetNpcAptitudes(unitNPC.data);
                                        //获取最优道魂
                                        foreach (NpcAptitude aptitude in npcAptitudes)
                                        {
                                            Il2CppSystem.Collections.Generic.List<DataProps.PropsData> daoHunGood = daoHunData.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                                            {
                                                int property = e.values[3];
                                                if (property == Convert.ToInt32(aptitude.Aptitude))
                                                {
                                                    return true;
                                                }
                                                else
                                                {
                                                    return false;
                                                }
                                            }));
                                            if (daoHunGood.Count > 0)
                                            {
                                                DataProps.PropsData daoHunLast = daoHunGood[0];
                                                unitNPC.data.RewardPropItem(daoHunLast, false);
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        unitNPC.data.RewardPropItem(item.propsID, item.propsCount, false);
                                    }

                                }
                                else
                                {
                                    unitNPC.data.RewardPropItem(item.propsID, item.propsCount, false);
                                }
                            }
                            //LogUtil.Log("太阳球MOD", "发放结束");
                        }
                    }
                }

            }

            catch (Exception ex)
            {
                LogUtil.Log("太阳球MOD", "【异常信息】" + ex.Message);
            }
        }

    }
}
